Skip to content

Conversation

ArneDefauw
Copy link
Contributor

spatialdata_plot.pl.render._render_labels still had sdata.table , changed to sdata.tables[table_name], otherwise colors passed via .uns where ignored.

also in

if adata is not None and cluster_key in adata.uns and f"{cluster_key}_colors" in adata.uns:

I would remove the check cluster_key in adata.uns. Because of this I had to set

    `sdata_blobs[ "other_table" ].uns[ "category" ] = "__value__"`

as a placeholder in https://github.com/ArneDefauw/spatialdata-plot/blob/b5cb0260c32a859783f87f10b8af05dc26feab76/tests/pl/test_render_labels.py#L219 .

I also stumbled upon a subtle bug while testing this feature. With the small fix in this PR, one can pass colors via .uns[ f"{cluster_key}_colors" ], and all works as expected, see
https://github.com/ArneDefauw/spatialdata-plot/blob/b5cb0260c32a859783f87f10b8af05dc26feab76/tests/pl/test_render_labels.py#L219

We get:
no_query

But if we do a bounding box query, we get:
query_fail

While we expect:
Figure_1

In short, this is caused by https://github.com/scverse/spatialdata/blob/03d3be80fad69ff54097e90a9e80ad02e9e0e242/src/spatialdata/_utils.py#L203

also see scverse/anndata#997

For details see https://github.com/ArneDefauw/spatialdata-plot/blob/b5cb0260c32a859783f87f10b8af05dc26feab76/tests/pl/test_render_labels.py#L227 and possible workaround https://github.com/ArneDefauw/spatialdata-plot/blob/b5cb0260c32a859783f87f10b8af05dc26feab76/tests/pl/test_render_labels.py#L252

Note that being able to plot a subset in the same colors as the orignal is a rather common use case. However, I am not sure where to fix. Maybe documenting the workaround suffices for now.

@LucaMarconato
Copy link
Member

Hi @ArneDefauw, thanks for the contribution. Two initial comments:

  • could you please open one issue describing what the PR addresses? This makes it easier to review and keeps a cleaner history of what a PR introduces. At the moment it's not immediate and one has to go and check the code and discussion. Or in alternative, without having to open an issue, can you please add a summary at the beginning of the PR of the issues being addressed? Thanks a lot!
  • I see some tests are not passing, one seems to be due to a difference between an old plot and the new one, while other seems to be due to raised exception. Do you have fix for them or comments on them?

Thanks!

@ArneDefauw
Copy link
Contributor Author

ArneDefauw commented Jan 28, 2025

Hi @LucaMarconato ,

I've linked an issue #414.

For the failed unit tests, there was a KeyError, because I overlooked that table_name can be None. I changed it in the PR.

For me all unit tests fail locally on the main branch of spatialdata-plot, so it is difficult to test. Therfore, I did not include base images for the unit tests I've added, because they would probably fail anyway in the CI/CD testing environment.

The unit tests I've added are for documentation of the issue, some of them can probably be removed when merging to main.

@LucaMarconato
Copy link
Member

Thanks for updating the PR! Regarding the failing tests, could you please give a try to the approach described here? https://github.com/scverse/spatialdata-plot/blob/main/docs/contributing.md

Locally generally the tests are reproducible on Ubuntu, but for other OS I use a Docker image, as described in the link above.

@LucaMarconato
Copy link
Member

My configuration with PyCharm is described here #397.

@codecov-commenter
Copy link

codecov-commenter commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.23%. Comparing base (43f25f6) to head (be331f3).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #413      +/-   ##
==========================================
+ Coverage   83.83%   84.23%   +0.40%     
==========================================
  Files           8        8              
  Lines        1732     1732              
==========================================
+ Hits         1452     1459       +7     
+ Misses        280      273       -7     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/utils.py 78.69% <ø> (+0.69%) ⬆️

@ArneDefauw
Copy link
Contributor Author

I managed to fix the tests (using a centOS server).

Note that I had to move this line

RNG = np.random.default_rng(seed=42)
inside
def _make_tablemodel_with_categorical_labels(self, sdata_blobs, labels_name: str):
, respectively
def test_plot_can_annotate_labels_with_table_layer(self, sdata_blobs: SpatialData):

to have the same results when running one test versus all the tests, because its internal state was moving forward due to multiple calls to it. Because of this I also had to update this figure https://github.com/scverse/spatialdata-plot/blob/main/tests/_images/Labels_can_annotate_labels_with_table_layer.png

@timtreis timtreis added priority: medium labels 🏷️ Anything related to Labels labels Jan 29, 2025
@LucaMarconato
Copy link
Member

Fantastic! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
labels 🏷️ Anything related to Labels priority: medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants